home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_130 / qman / qman.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  9KB  |  377 lines

  1. #include "INCLUDE:Lattice/math.h"
  2. #include "INCLUDE:Lattice/stdio.h"
  3. #include "INCLUDE:libraries/dos.h"
  4. #include "INCLUDE:exec/types.h"
  5. #include "INCLUDE:graphics/gfx.h"
  6. #include "INCLUDE:graphics/gfxmacros.h"
  7. #include "INCLUDE:exec/exec.h"
  8. #include "INCLUDE:exec/execbase.h"
  9. #include "INCLUDE:graphics/view.h"
  10. #include "INCLUDE:graphics/gfxbase.h"
  11. #include "INCLUDE:graphics/text.h"
  12. #include "INCLUDE:exec/libraries.h"
  13. #include "INCLUDE:intuition/intuition.h"
  14.  
  15. #include "qman_data.include"
  16.  
  17. /*---------------------------------------*/
  18. /*                                       */
  19. /*           //   QMan !   //            */
  20. /*                                       */
  21. /*    (That's supposed to stand for      */
  22. /*        "Quick Mandelbrot.")           */
  23. /*---------------------------------------*/
  24.  
  25. void main()
  26. {
  27.  
  28. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  29. IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  30.  
  31.  
  32. scale = 67108864.0;     /*    2 ** 26   */
  33. xptr = (int)&x_table[0];
  34.  
  35. kflag = 1;   /*   start off looking at the skew set  */
  36.  
  37. Restart:
  38.  
  39. restart_selected = FALSE;
  40.  
  41. top     =  1.1;
  42. bottom  = -1.1;
  43.  
  44. if ( kflag == 1 ) {
  45.   left  = -1.5;
  46.   right =  1.0;   }
  47. else              {
  48.   left  = -2.0;
  49.   right =  0.5;   }
  50.  
  51. random_colors = FALSE;
  52.  
  53. cycle_colors =   1;   /*  initially cycle colors       */
  54. ilace        =   2;   /*  start out without interlace  */
  55. vertical_res = 200;
  56. smooth_flag  =   1;   /*  smoothing is initially on    */
  57.  
  58.  
  59. NewScreen:
  60.  
  61.   SetUpMandelGraphics();
  62.  
  63.   SetUpMandelMenus();
  64.  
  65.   SetMenuStrip( mandel_window, &qman  ); 
  66.  
  67.  
  68. screen_changed = FALSE;
  69.  
  70. while (1 == 1) {
  71.  
  72.   NextPicture:
  73.  
  74.   Move( rp, 0, 0  );
  75.   ClearScreen( rp );
  76.  
  77.   xincr   =  (right - left)/640.0;
  78.   yincr   =  (top - bottom)/(double)vertical_res;
  79.  
  80.   left_x  = left;
  81.  
  82.   for (i = 0; i < 640; i++ )  {
  83.     x_table[i] = scale * left_x;
  84.     left_x = left_x + xincr;      }
  85.  
  86.   imagc = scale * top;
  87.  
  88.   /*  Set bit plane pointers for next Mandelbrot picture:  */
  89.   bp1 = (int) rp -> BitMap -> Planes[0];
  90.   bp2 = (int) rp -> BitMap -> Planes[1];
  91.   bp3 = (int) rp -> BitMap -> Planes[2];
  92.   bp4 = (int) rp -> BitMap -> Planes[3]; 
  93.  
  94.   new_region_selected = FALSE;
  95.  
  96.   for ( y = 0; y < vertical_res; y++ ) {
  97.  
  98.     message = (struct IntuiMessage *) GetMsg( mandel_window -> UserPort );
  99.  
  100.  
  101.     if ( message != NULL ) {
  102.       ProcessMessage();  
  103.  
  104.       if ( new_region_selected ) goto NextPicture;
  105.       if ( screen_changed      ) goto NewScreen; 
  106.       if ( restart_selected    ) goto Restart;    }
  107.  
  108.  
  109.     if ( cycle_colors == 1 ) NextColor();
  110.  
  111.     /* Call the appropriate assembly routine to draw the current row: */
  112.     if ( smooth_flag == 1 ) 
  113.       msmooth();
  114.     else
  115.       mandel(); 
  116.  
  117.     imagc = imagc - scale * yincr;
  118.  
  119.     }  /* y-loop */
  120.  
  121.  
  122.     /* - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  123.     cycle_count = 0;
  124.  
  125.     while( 1 == 1 ) { 
  126.       cycle_count = (cycle_count + 1) % 4000;
  127.  
  128.       if ( (cycle_count == 0) && (cycle_colors == 1) ) NextColor();  
  129.  
  130.       message = (struct IntuiMessage *) GetMsg( mandel_window -> UserPort );
  131.  
  132.       if ( message != NULL ) {
  133.         ProcessMessage();  
  134.  
  135.         if ( new_region_selected ) goto NextPicture;
  136.         if ( screen_changed      ) goto NewScreen;  
  137.         if ( restart_selected    ) goto Restart;   }
  138.  
  139.         } /* inner forever loop */
  140.     /* - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  141.  
  142.   }   /* outer forever loop  */
  143.  
  144.  
  145. }  /* main */
  146.  
  147. /*--------------------------------------------*/
  148.  
  149. #include "qman_graphics.include"
  150. #include "qman_menus.include"
  151.  
  152. /*--------------------------------------------*/
  153.  
  154. void ProcessMessage()
  155. {
  156.   struct MenuItem  *Item;
  157.  
  158.   if ( message -> Class != MENUPICK ) return;
  159.   if ( message -> Code  == MENUNULL ) return;
  160.  
  161.   Item = (struct MenuItem *)ItemAddress( &qman, message -> Code );
  162.  
  163.   if ( Item -> Command == 'q' ) {
  164.     CloseWindow( mandel_window );
  165.     CloseScreen( mandel_screen );
  166.     exit();
  167.     } 
  168.  
  169.   if ( Item -> Command == 'n' )  NextColor();
  170.   if ( Item -> Command == 'b' )  random_colors = FALSE;
  171.   if ( Item -> Command == 'r' )  random_colors = TRUE;
  172.  
  173.  
  174.  
  175.   if ( Item -> Command == 'c' )            {  /* toggle cycle option:  */
  176.  
  177.     ClearMenuStrip( mandel_window );
  178.  
  179.     if ( cycle_colors == 1 )                  /* cycling currently on  */
  180.       cycle.Flags = cycle.Flags ^ CHECKED;    /* turn cycling off      */
  181.     else
  182.       cycle.Flags = cycle.Flags | CHECKED;    /* turn cycling on       */
  183.  
  184.     cycle_colors =   3 - cycle_colors;
  185.  
  186.     SetMenuStrip( mandel_window, &qman );  } 
  187.  
  188.  
  189.   if ( Item -> Command == 'm' )            {  /* toggle smoothing option: */
  190.  
  191.     ClearMenuStrip( mandel_window );
  192.  
  193.     if ( smooth_flag == 1 )                   /* smoothing currently on   */
  194.       smooth.Flags = smooth.Flags ^ CHECKED;  /* turn smoothing off       */
  195.     else
  196.       smooth.Flags = smooth.Flags | CHECKED;  /* turn smoothing on        */
  197.  
  198.     smooth_flag = 3 - smooth_flag;
  199.  
  200.     SetMenuStrip( mandel_window, &qman );  } 
  201.  
  202.  
  203.   if ( Item -> Command == 'k' )            {  /* toggle skew option:      */
  204.  
  205.     ClearMenuStrip( mandel_window );
  206.  
  207.     if ( kflag == 1 )                         /* skew currently on   */
  208.       skew.Flags = skew.Flags ^ CHECKED;      /* turn skew off       */
  209.     else
  210.       skew.Flags = skew.Flags | CHECKED;      /* turn skew on        */
  211.  
  212.     kflag = 1 - kflag;
  213.  
  214.     SetMenuStrip( mandel_window, &qman );  }  
  215.  
  216.  
  217.     if ( Item -> Command == 'i' )      { /* toggle ilace option:   */
  218.       ilace   =   3 - ilace;
  219.       vertical_res = 600 - vertical_res;
  220.       screen_changed = TRUE;
  221.       CloseWindow( mandel_window );
  222.       CloseScreen( mandel_screen );    }
  223.  
  224.   if ( Item -> Command == 's' )        {
  225.      restart_selected = TRUE;
  226.      CloseWindow( mandel_window );
  227.      CloseScreen( mandel_screen );     } 
  228.          
  229.   if ( Item -> Command == 'z' )  SelectZoom();
  230.  
  231.   ReplyMsg( message );
  232.  
  233. }  /*  end of ProcessMessage()    */
  234.  
  235. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  236.  
  237. void NextColor()
  238. {
  239.    int permute, greenzap;
  240.  
  241.    if ( random_colors )            {
  242.        for( i = 3; i < 13; i++)                {
  243.          reds[i]   = lrand48() % 16;
  244.          greens[i] = lrand48() % 16;
  245.          blues[i]  = lrand48() % 16;
  246.          SetRGB4( vp, i, reds[i], greens[i], blues[i] );   }
  247.                                     }  /* random colors */
  248.  
  249.     else {  /* generate the colors a little less chaotically! */
  250.          reds[3]   = lrand48() % 16;
  251.          greens[3] = lrand48() % 16;
  252.          blues[3]  = lrand48() % 16;
  253.          greenzap  = lrand48() % 12;
  254.          permute   = lrand48() %  6;
  255.  
  256.          for( i = 4; i < 13; i++)               { 
  257.            reds[i]   = (reds[i-1]   +  1) % 16;
  258.            greens[i] = (greens[i-1] + 15) % 16;
  259.            if ( greenzap == 0 ) greens[i] = 0;
  260.            blues[i]  = blues[3];
  261.  
  262.            switch( permute ) {
  263.  
  264.              case 0 :  SetRGB4(vp,i,reds[i],greens[i],blues[i]);  break; 
  265.              case 1 :  SetRGB4(vp,i,reds[i],blues[i],greens[i]);  break; 
  266.              case 2 :  SetRGB4(vp,i,greens[i],reds[i],blues[i]);  break;
  267.              case 3 :  SetRGB4(vp,i,greens[i],blues[i],reds[i]);  break;
  268.              case 4 :  SetRGB4(vp,i,blues[i],reds[i],greens[i]);  break;
  269.              case 5 :  SetRGB4(vp,i,blues[i],greens[i],reds[i]);  break;
  270.  
  271.                              }  /* switch */
  272.                                                }  /*  i-loop  */
  273.  
  274.          }    /*   else   */ 
  275.  
  276.  
  277. }  /* End of NextColor  */
  278.  
  279. /* - - - - - - - - - - - - - - - - - - - - - - - - - */
  280.  
  281. void SelectZoom()
  282.  
  283. {
  284.   struct IntuiMessage *click, *click2;
  285.   int    IDCMP_flags, s3, t3;
  286.   SHORT  quad[10];
  287.   
  288.  
  289.   SetDrMd( rp, COMPLEMENT );
  290.   SetAPen( rp, 1 );
  291.  
  292.   new_region_selected = TRUE;
  293.  
  294.  
  295.   UpperLeft:
  296.  
  297.   WaitPort( mandel_window -> UserPort );
  298.   click = (struct IntuiMessage *) GetMsg( mandel_window -> UserPort );
  299.  
  300.   if ( click -> Code != SELECTDOWN ) {
  301.     ReplyMsg( click );
  302.     goto UpperLeft;                  }
  303.  
  304.   left  = left + xincr * (double)click -> MouseX;
  305.   top   = top  - yincr * (double)click -> MouseY;
  306.  
  307.   x1 = click -> MouseX;
  308.   y1 = click -> MouseY;
  309.   x3 = x1;
  310.   y3 = y1; 
  311.  
  312.  
  313.   IDCMP_flags = MOUSEBUTTONS | MENUPICK | MOUSEMOVE;
  314.   ModifyIDCMP( mandel_window, IDCMP_flags ); 
  315.  
  316.   Move( rp, x1, y1 );
  317.   quad[3] = y1;
  318.   quad[6] = x1;
  319.   quad[8] = x1;
  320.   quad[9] = y1;
  321.  
  322.   LowerRight:
  323.  
  324.   WaitPort( mandel_window -> UserPort );
  325.   click  = (struct IntuiMessage *) GetMsg( mandel_window -> UserPort );
  326.  
  327.   click2 = (struct IntuiMessage *) GetMsg( mandel_window -> UserPort );
  328.   if (click2 != NULL ) {
  329.     ReplyMsg( click );
  330.     click = click2;    }
  331.  
  332.   if ( click -> Code != SELECTUP )  {
  333.     s3 = click -> MouseX;
  334.     t3 = click -> MouseY;
  335.  
  336.     ReplyMsg( click );
  337.  
  338.     if ( (s3 < x1) || (t3 < y1) ) goto LowerRight;
  339.  
  340.     x2 = x3;
  341.     y2 = y3;
  342.     x3 = s3;
  343.     y3 = t3;
  344.  
  345.     quad[2] = x2;
  346.     quad[4] = x2;
  347.     quad[5] = y2;
  348.     quad[7] = y2;
  349.  
  350.     PolyDraw( rp, 4, &quad[2] );
  351.  
  352.     quad[2] = x3;
  353.     quad[4] = x3;
  354.     quad[5] = y3;
  355.     quad[7] = y3; 
  356.  
  357.     PolyDraw( rp, 4, &quad[2] );
  358.  
  359.     goto LowerRight;                }
  360.  
  361.   else ReplyMsg( click );
  362.  
  363.  
  364.   right  = right   - xincr * (double)(640          - click -> MouseX);
  365.   bottom = bottom  + yincr * (double)(vertical_res - click -> MouseY);
  366.  
  367.   IDCMP_flags = MOUSEBUTTONS | MENUPICK;
  368.   ModifyIDCMP( mandel_window, IDCMP_flags );
  369.  
  370.   SetDrMd( rp, JAM1 ); 
  371.  
  372.  
  373. }
  374.  
  375.  
  376.  
  377.